package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.service.IYwYhService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YwBl;
import com.ruoyi.system.service.IYwBlService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病历管理Controller
 * 
 * @author ruoyi
 * @date 2022-04-21
 */
@Controller
@RequestMapping("/system/bl")
public class YwBlController extends BaseController
{
    private String prefix = "system/bl";

    @Autowired
    private IYwBlService ywBlService;
    @Autowired
    private IYwYhService ywYhService;

    @RequiresPermissions("system:bl:view")
    @GetMapping()
    public String bl()
    {
        return prefix + "/bl";
    }

    /**
     * 查询病历管理列表
     */
    @RequiresPermissions("system:bl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YwBl ywBl)
    {
        startPage();
        List<YwBl> list = ywBlService.selectYwBlList(ywBl);
        return getDataTable(list);
    }

    /**
     * 导出病历管理列表
     */
    @RequiresPermissions("system:bl:export")
    @Log(title = "病历管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YwBl ywBl)
    {
        List<YwBl> list = ywBlService.selectYwBlList(ywBl);
        ExcelUtil<YwBl> util = new ExcelUtil<YwBl>(YwBl.class);
        return util.exportExcel(list, "病历管理数据");
    }

    /**
     * 新增病历管理
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {

        System.out.println(ywYhService.list());
        mmap.put("yhs",ywYhService.list());
        return prefix + "/add";
    }

    /**
     * 新增保存病历管理
     */
    @RequiresPermissions("system:bl:add")
    @Log(title = "病历管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YwBl ywBl)
    {
        return toAjax(ywBlService.insertYwBl(ywBl));
    }

    /**
     * 修改病历管理
     */
    @RequiresPermissions("system:bl:edit")
    @GetMapping("/edit/{blId}")
    public String edit(@PathVariable("blId") Long blId, ModelMap mmap)
    {
        YwBl ywBl = ywBlService.selectYwBlByBlId(blId);
        mmap.put("ywBl", ywBl);
        return prefix + "/edit";
    }

    /**
     * 修改保存病历管理
     */
    @RequiresPermissions("system:bl:edit")
    @Log(title = "病历管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YwBl ywBl)
    {
        return toAjax(ywBlService.updateYwBl(ywBl));
    }
    /**
     * 删除病历管理
     */
    @RequiresPermissions("system:bl:remove")
    @Log(title = "病历管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ywBlService.deleteYwBlByBlIds(ids));
    }
}
